const redis = require('redis');
const config = require('./config');
const m = require('./logger');

clients = redis.createClient(config.redis.port, config.redis.ip,{
    auth_pass: config.redis.pwd,
    retry_strategy: function (options) {
        if (options.error.code === 'ECONNREFUSED') {
            m.logger.error('连接被拒绝');
        }
        if (options.times_connected > 10) {
            m.logger.error('重试连接超过十次');
        }
        return Math.max(options.attempt * 100, 3000);
    }
});
clients.on("error", (err) => {
    m.logger.error("redis error %s.",err.toString());
});

module.exports = clients;

